package com.zf.helm.controller;

import com.zf.helm.entity.Student;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @author Zhou Feng
 */
@Slf4j
@RequestMapping("/stu")
@RestController
public class StudentController {

    @GetMapping("/randomOne")
    public Student randomOne(HttpServletRequest request) {
        int age = ThreadLocalRandom.current().nextInt(18, 21);
        String[] names = {"李四", "王五", "赵六"};
        String[] grades = {"大一", "大二", "大三"};
        Student student = new Student();
        student.setAge(age);
        student.setName(names[age % 3]);
        student.setGrade(grades[age % 3]);
        log.info("调用了 {}, 响应是：{}", request.getRequestURI(), student);
        return student;
    }
}
